
;;org-mode export to latex, refer: https://emacs-china.org/t/spacemacs-org-mode-pdf/1577
  (require 'ox-latex)
  (setq org-export-latex-listings t)

  ;;org-mode source code setup in exporting to latex
  (add-to-list 'org-latex-listings '("" "listings"))
  (add-to-list 'org-latex-listings '("" "color"))

  (add-to-list 'org-latex-packages-alist
               '("" "xcolor" t))
  (add-to-list 'org-latex-packages-alist
               '("" "listings" t))
  (add-to-list 'org-latex-packages-alist
               '("" "fontspec" t))
  (add-to-list 'org-latex-packages-alist
               '("" "indentfirst" t))
  (add-to-list 'org-latex-packages-alist
               '("" "xunicode" t))
  (add-to-list 'org-latex-packages-alist
               '("" "geometry"))
  (add-to-list 'org-latex-packages-alist
               '("" "float"))
  (add-to-list 'org-latex-packages-alist
               '("" "longtable"))
  (add-to-list 'org-latex-packages-alist
               '("" "tikz"))
  (add-to-list 'org-latex-packages-alist
               '("" "fancyhdr"))
  (add-to-list 'org-latex-packages-alist
               '("" "textcomp"))
  (add-to-list 'org-latex-packages-alist
               '("" "amsmath"))
  (add-to-list 'org-latex-packages-alist
               '("" "amsthm"))
  (add-to-list 'org-latex-packages-alist
               '("" "tabularx" t))
  (add-to-list 'org-latex-packages-alist
               '("" "booktabs" t))
  (add-to-list 'org-latex-packages-alist
               '("" "grffile" t))
  (add-to-list 'org-latex-packages-alist
               '("" "wrapfig" t))
  (add-to-list 'org-latex-packages-alist
               '("normalem" "ulem" t))
  (add-to-list 'org-latex-packages-alist
               '("" "amssymb" t))
  (add-to-list 'org-latex-packages-alist
               '("" "capt-of" t))
  (add-to-list 'org-latex-packages-alist
               '("figuresright" "rotating" t))
  (add-to-list 'org-latex-packages-alist
               '("Lenny" "fncychap" t))

  (add-to-list 'org-latex-classes
               '("zhcosin-org-book"
                 "\\documentclass{ctexbook}
\\usepackage{titlesec}
\\usepackage{hyperref}

[NO-DEFAULT-PACKAGES]
[PACKAGES]

\\newtheorem{theorem}{定理}[section]

%\\setCJKmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
%\\setCJKsansfont{WenQuanYi Micro Hei}
%\\setCJKmonofont{WenQuanYi Micro Hei Mono}

%\\setmainfont{DejaVu Sans} % 英文衬线字体
%\\setsansfont{DejaVu Serif} % 英文无衬线字体
%\\setmonofont{DejaVu Sans Mono}
%\\setmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
%\\setsansfont{WenQuanYi Micro Hei}
%\\setmonofont{WenQuanYi Micro Hei Mono}

%如果没有它，会有一些 tex 特殊字符无法正常使用，比如连字符。
\\defaultfontfeatures{Mapping=tex-text}

% 中文断行
\\XeTeXlinebreaklocale \"zh\"
\\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt

% 代码设置
\\lstset{numbers=left,
numberstyle= \\tiny,
keywordstyle= \\color{ blue!70},commentstyle=\\color{red!50!green!50!blue!50},
frame=shadowbox,
breaklines=true,
rulesepcolor= \\color{ red!20!green!20!blue!20}
}

[EXTRA]
"
                 ("\\chapter{%s}" . "\\chapter*{%s}")
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" . "\\subsection*{%s}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                 ("\\paragraph{%s}" . "\\paragraph*{%s}")
                 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

  (add-to-list 'org-latex-classes
               '("zhcosin-org-article"
                 "\\documentclass{ctexart}
\\usepackage{titlesec}
\\usepackage{hyperref}

[NO-DEFAULT-PACKAGES]
[PACKAGES]

\\newtheorem{theorem}{定理}[section]

\\parindent 2em

%\\setCJKmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
%\\setCJKsansfont{WenQuanYi Micro Hei}
%\\setCJKmonofont{WenQuanYi Micro Hei Mono}

%\\setmainfont{DejaVu Sans} % 英文衬线字体
%\\setsansfont{DejaVu Serif} % 英文无衬线字体
%\\setmonofont{DejaVu Sans Mono}
%\\setmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
%\\setsansfont{WenQuanYi Micro Hei}
%\\setmonofont{WenQuanYi Micro Hei Mono}

%如果没有它，会有一些 tex 特殊字符无法正常使用，比如连字符。
\\defaultfontfeatures{Mapping=tex-text}

% 中文断行
\\XeTeXlinebreaklocale \"zh\"
\\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt

% 代码设置
\\lstset{numbers=left,
numberstyle= \\tiny,
keywordstyle= \\color{ blue!70},commentstyle=\\color{red!50!green!50!blue!50},
frame=shadowbox,
breaklines=true,
rulesepcolor= \\color{ red!20!green!20!blue!20}
}

[EXTRA]
"
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" . "\\subsection*{%s}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                 ("\\paragraph{%s}" . "\\paragraph*{%s}")
                 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

  (add-to-list 'org-latex-classes
               '("zhcosin-org-beamer"
                 "\\documentclass{beamer}
\\usepackage[slantfont, boldfont]{xeCJK}
% beamer set
\\usepackage[none]{hyphenat}
\\usepackage[abs]{overpic}

[NO-DEFAULT-PACKAGES]
[PACKAGES]

\\newtheorem{theorem}{定理}[section]

\\setCJKmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
\\setCJKsansfont{WenQuanYi Micro Hei}
\\setCJKmonofont{WenQuanYi Micro Hei Mono}

\\setmainfont{DejaVu Sans} % 英文衬线字体
\\setsansfont{DejaVu Serif} % 英文无衬线字体
\\setmonofont{DejaVu Sans Mono}
%\\setmainfont{WenQuanYi Micro Hei} % 设置缺省中文字体
%\\setsansfont{WenQuanYi Micro Hei}
%\\setmonofont{WenQuanYi Micro Hei Mono}

%如果没有它，会有一些 tex 特殊字符无法正常使用，比如连字符。
\\defaultfontfeatures{Mapping=tex-text}

% 中文断行
\\XeTeXlinebreaklocale \"zh\"
\\XeTeXlinebreakskip = 0pt plus 1pt minus 0.1pt

% 代码设置
\\lstset{numbers=left,
numberstyle= \\tiny,
keywordstyle= \\color{ blue!70},commentstyle=\\color{red!50!green!50!blue!50},
frame=shadowbox,
breaklines=true,
rulesepcolor= \\color{ red!20!green!20!blue!20}
}

[EXTRA]
"
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" . "\\subsection*{%s}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                 ("\\paragraph{%s}" . "\\paragraph*{%s}")
                 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

  (setq org-latex-pdf-process
        '("xelatex -interaction nonstopmode -output-directory %o %f"
          ;;"biber %b" "xelatex -interaction nonstopmode -output-directory %o %f"
          "bibtex %b"
          "xelatex -interaction nonstopmode -output-directory %o %f"
          "xelatex -interaction nonstopmode -output-directory %o %f"))

 (provide 'init-org2pdf)
